﻿CREATE PROCEDURE [dbo].[ReportPMWeeklySummary]
@startDate DATETIME,
@managerID int
AS
BEGIN
	SELECT        u.FullName, Projects.Name, EntryLog.EntryDate, EntryLog.Description, EntryLog.Duration
	FROM          EntryLog INNER JOIN
	      			  (SELECT DISTINCT u.[UserID], u.FullName, u.UserName
					   FROM [dbo].[Projects] AS p
					   INNER JOIN [dbo].[ProjectMembers] AS pm ON p.[ProjectID] = pm.[ProjectID]
					   INNER JOIN [dbo].[Users] AS u ON u.[UserID] = pm.[UserID]
					   WHERE p.[ManagerUserID] = @managerID) as u ON EntryLog.UserID = u.UserID INNER JOIN
				  Projects ON Projects.ProjectID = EntryLog.ProjectID
	WHERE        (EntryLog.EntryDate > @startDate) and (EntryLog.EntryDate < DATEADD(dd, 7, @startDate)) and Projects.ManagerUserID = @managerID
	ORDER BY u.UserName, Projects.Name, EntryLog.EntryDate
END